package com.jming.common.easycaptcha;

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {

    @Autowired
    private CaptchaRepository captchaRepository;

    public boolean verifyCaptcha(String captchaCode) {
        // 根据验证码获取记录
        Captcha captcha = captchaRepository.findByCode(captchaCode);

        // 判断验证码是否过期
        if (captcha == null || captcha.getExpireTime().isBefore(LocalDateTime.now())) {
            return false;
        }

        // 删除验证码记录
        captchaRepository.delete(captcha);

        return true;
    }

}